<template>
  <div style="width: 400px; height: 350px; margin: 150px auto; background-color:rgba(107,149,224,0.5); border-radius: 10px">
    <div style="width: 100%; height: 100px; font-size: 30px; line-height: 100px; text-align: center; color: #4a5ed0">校园树洞，欢迎登录</div>
    <div style="margin-top: 25px; text-align: center; height: 320px;">
      <el-form :model="admin">
        <el-form-item>
          <el-input v-model="admin.userName" prefix-icon="el-icon-user" style="width: 80%" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="admin.passWord" show-password prefix-icon="el-icon-lock" style="width: 80%" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <div style="    display: flex;flex-direction: row;align-items: center;padding-left: 30px;padding-right: 30px;">
            <el-button style="width: 80%; margin-top: 10px" type="primary" @click="login()">登录</el-button>
            <el-button style="width: 80%; margin-top: 10px" type="primary" @click="regist()">注册</el-button>
          </div>
          <div style="color: #1890ff;text-decoration: none;background-color: transparent;outline: none;cursor: pointer; display: flex; padding-left: 30px;">
            忘记密码》》》》
          </div>
        </el-form-item>
      </el-form>
      </div>
    </div>
  
</template>
<style>
body {
      background: url('https://img-baofun.zhhainiao.com/market/238/c4302c9a3921d2f88b1322dc6173915d_preview.jpg') no-repeat;
      background-size: 100% 130%;
    } 

</style>
<script>
import request from "@/utils/request";

export default {
  name: "Login",
  data() {
    return {
      admin: {}
    }
  },
  // 页面加载的时候，做一些事情，在created里面
  created() {
  },
  // 定义一些页面上控件出发的事件调用的方法
  methods: {
    login() {
      request.post("/admin/login", this.admin).then(res => {
        if (res.code === 1 ) {
          this.$message({
            message: '登录成功',
            type: 'success'
          });
          localStorage.setItem("user",JSON.stringify(res.data))
          this.$router.push("/");
        } else {
          this.$message({
            message: res.msg,
            type: 'error'
          });
        }
      })
    },
    regist(){
      this.$router.push("/regist");
    }
  }
}

</script> 